package com.bird.system.remote.menu

import com.bird.component.lang.common.response.JSONResponse
import com.bird.component.lang.common.response.success
import com.bird.component.log.WebLog
import com.bird.system.application.menu.MenuCommandService
import com.bird.system.application.menu.MenuQueryService
import com.bird.system.application.menu.pl.*
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/menus")
class MenuController(
    private val menuCommandService: MenuCommandService,
    private val menuQueryService: MenuQueryService
) {

    /**
     * 添加菜单
     */
    @PostMapping("/addMenu")
    fun addMenu(@RequestBody addMenuRequest: AddMenuRequest): JSONResponse<Unit> {
        return  success{
            // 添加菜单
            menuCommandService.addMenu(addMenuRequest)
        }
    }
    /**
     * 更新菜单
     */
    @PostMapping("/updateMenu")
    fun updateMenu(@RequestBody updateMenuRequest: UpdateMenuRequest): JSONResponse<Unit> {
        // 更新菜单
        menuCommandService.updateMenu(updateMenuRequest)
        return success()
    }
    /**
     * 删除菜单
     */
    @PostMapping("/deleteMenu")
    fun deleteMenu(@RequestParam("menuId") menuId: Long): JSONResponse<Unit> {
        // 删除菜单
        menuCommandService.deleteMenu(menuId)
        return success()
    }
    /**
     * 查询菜单列表
     */
    @WebLog("查询菜单列表")
    @GetMapping("/listMenu")
    fun listMenu(): JSONResponse<List<ListMenuResponse>> {
        return success{
            menuQueryService.listMenu()
        }
    }





}